package com.logos.cartoon.handler;

import com.logos.cartoon.enums.AiModelEnum;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ai模型类型工厂
 */
@Component
public class AiModelHandlerFactory implements InitializingBean {

    @Resource
    private List<AiModelHandler> aiModelTypeHandlerList;

    private Map<AiModelEnum, AiModelHandler> handlerMap = new HashMap<>();

    public  AiModelHandler getHandler(Long aiModelType) {
        AiModelEnum aiModelTypeEnum = AiModelEnum.getByCode(aiModelType);
        return handlerMap.get(aiModelTypeEnum);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        for (AiModelHandler aiModelTypeHandler : aiModelTypeHandlerList) {
            handlerMap.put(aiModelTypeHandler.getHandlerType(), aiModelTypeHandler);
        }
    }
}
